package com.situ.project1.controller;

import com.github.pagehelper.PageInfo;
import com.situ.project1.pojo.Account;
import com.situ.project1.pojo.Car;
import com.situ.project1.pojo.search.CarSearchModel;
import com.situ.project1.service.ManagerService;
import com.situ.project1.util.PaginateInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author:yzy
 * @date:2024/8/20
 */
@RestController
@RequestMapping("/api/manager")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    @GetMapping
    public Map<String,Object> findAll(
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize,
            Account account
    ){
        if (pageNo==null||pageNo<1){
            pageNo=1;
        }
        if (pageSize==null||pageSize<1){
            pageSize=10;
        }
        PaginateInfo pi =new PaginateInfo(pageNo,pageSize);
        List<Account> accounts = managerService.findAll(pi,account);

        PageInfo pif = new PageInfo<>(accounts);
        Map<String,Object> map = Map.of("total",pif.getTotal(),"pageNo",pif.getPageNum(),"pageSize",pif.getPageSize());
        return Map.of("success",true,"rows",accounts,"pi",map);
    }
}
